<?
if (!defined('IN_RJ')) die("Error 404");
if($cmd[1]=="cat" && is_numeric($cmd[2])){
$cat_id=$cmd[2];
if((!is_numeric($cmd[3])) && !$cmd[3]) $cmd[3]=1;
$perpage=18;
$limit=($cmd[3]-1)*$perpage;
$q_chk=$DB->query("SELECT sub_id,cat_type,cat_name,cat_name_ascii FROM ".$conf['prefix']."cat WHERE cat_id = '{$cat_id}'");
$check = $DB->fetch_row($q_chk);
$title_web_bar=$check['cat_name'];
$title_ascii_web_bar=$check['cat_name_ascii'];
$type_cat_to_banner="music";
if($check['cat_type']==1){
	if (!is_null($check['sub_id']) && $check['sub_id'] != 0) {
		$sql=$DB->query("SELECT * FROM {$conf['prefix']}media WHERE (m_multimedia=0 OR m_multimedia IN (select multi_id from {$conf['prefix']}multimedia where multi_type=1)) AND m_cat='{$cat_id}' ORDER BY m_id DESC LIMIT {$limit},{$conf['media_per_page']}");
		$sql_tt=$DB->query("SELECT * FROM {$conf['prefix']}media WHERE (m_multimedia=0 OR m_multimedia IN (select multi_id from {$conf['prefix']}multimedia where multi_type=1)) AND m_cat='{$cat_id}' ORDER BY m_id DESC");
		$tt=$DB->num_rows($sql_tt);
	}
	
	else{
			$list_q = $DB->query("SELECT cat_id FROM ".$conf['prefix']."cat WHERE sub_id = '{$cat_id}' AND cat_type=1");
			$in_sql = '';
			while ($list_ro = $DB->fetch_row($list_q)) $in_sql .= "'".$list_ro['cat_id']."',";
			$in_sql = substr($in_sql,0,-1);
			if (!$in_sql) $in_sql = -1;
		$sql=$DB->query("SELECT * FROM {$conf['prefix']}media WHERE (m_multimedia=0 OR m_multimedia IN (select multi_id from {$conf['prefix']}multimedia where multi_type=1)) AND m_cat IN ({$in_sql}) ORDER BY m_id DESC LIMIT {$limit},{$conf['media_per_page']}");
		$sql_tt=$DB->query("SELECT * FROM {$conf['prefix']}media WHERE (m_multimedia=0 OR m_multimedia IN (select multi_id from {$conf['prefix']}multimedia where multi_type=1)) AND m_cat IN ({$in_sql}) ORDER BY m_id DESC");
		$tt=$DB->num_rows($sql_tt);
	}


	if ($tt) {
		$ro = $tpl->get_tpl('list_media');
		$t['row'] = $tpl->get_block_from_str($ro,'list_media.row',1);
		
		$html = '';
		$list_title=$check['cat_name'];
		$list_title_ascii=$check['cat_name_ascii'];
		while ($song = $DB->fetch_row($sql)) {
			static $i = 0;	
			$singer_name=$func->get_data('singer',$song['m_singer']);
			$html .= $tpl->assign_vars($t['row'],
				array(
				'song.TITLE'	=> $func->unhtmlchars($song['m_title']),
				'song.TYPE'		=> "<img src='{TPL_LINK}/".$func->get_data('player',$song['m_type'])."' border=0 >",
				'song.ID'		=> $song['m_id'],	
				'song.VIEWED'	=> $song['m_viewed'],
				'song.DOWNLOADED' => $song['m_downloaded'],
				'song.SINGER_NAME' => $singer_name,
				'song.SINGER_URL' => $func->change_link('singer',$song['m_singer'],$func->title_2_ascii($singer_name,true)),
				'song.URL'		=> $func->change_link('song',$song['m_id'],$func->title_2_ascii($song['m_title_ascii'])),
				'song.ADD_PL'	=> $logged_in?"select_playlist({$song['m_id']});return false;":"guest_add_playlist({$song['m_id']});return false;",
				)
			);
			$i++;
		}
		$ro = $tpl->assign_vars($ro,
			array(
				'list.CAT_ID'=> $cat_id,
				'list.TITLE' => $list_title,
				'list.TOTAL'	=> "{$lang['total']} {$tt} {$lang['song']}",
				'list.PAGES' => $func->viewpages($tt,$conf['media_per_page'],$cmd[3],$list_title_ascii),
			)
		);
		
		$ro = $tpl->assign_blocks_content($ro,array(
				'list_media'	=>	$html,
			)
		);
		
	} 
	else $ro=box_announcement($lang['no_data']);
	$main_content=$ro;
}
else{

	if (!is_null($check['sub_id']) && $check['sub_id'] != 0) {
	
		$sql=$DB->query("SELECT * FROM {$conf['prefix']}multimedia WHERE multi_cat='{$cat_id}' AND multi_type=2 ORDER BY multi_id DESC LIMIT {$limit},{$perpage}");
		$sql_tt=$DB->query("SELECT * FROM {$conf['prefix']}multimedia WHERE multi_cat='{$cat_id}' AND multi_type=2 ORDER BY multi_id DESC");
		$tt=$DB->num_rows($sql_tt);
	}
	
	else{
			$list_q = $DB->query("SELECT cat_id FROM ".$conf['prefix']."cat WHERE sub_id = '{$cat_id}' AND cat_type=2");
			$in_sql = '';
			while ($list_ro = $DB->fetch_row($list_q)) $in_sql .= "'".$list_ro['cat_id']."',";
			$in_sql = substr($in_sql,0,-1);
			if (!$in_sql) $in_sql = -1;
		$sql=$DB->query("SELECT * FROM {$conf['prefix']}multimedia WHERE multi_cat IN ($in_sql) AND multi_type=2 ORDER BY multi_id DESC LIMIT {$limit},{$perpage}");
		$sql_tt=$DB->query("SELECT * FROM {$conf['prefix']}multimedia WHERE multi_cat IN ($in_sql) AND multi_type=2 ORDER BY multi_id DESC");
		$tt=$DB->num_rows($sql_tt);
	}

	if ($tt) {
		$cat_tit = $func->get_data('cat',$cat_id);
		$z = $tpl->get_tpl('list_multimedia');
		$t['row'] = $tpl->get_block_from_str($z,'list_multi.row',1);
		
		$html = '';
		while ($r = $DB->fetch_row($sql)) {
			static $i = 0;
			$tr= (fmod($i,3) == 0)?'</tr><tr>':'';
			$multi_img = $func->get_img('multimedia',$r['multi_id']);
			$tit_ascii=$func->title_2_ascii($r['multi_name_ascii']);
				$link=$func->change_link("movie",$r['multi_id'],$tit_ascii);
				$total=$lang['have_total']." <b>{$tt}</b> ".$lang['movie'];
			$html .= $tpl->assign_vars($t['row'],
				array(
					'multi.IMG'		=>	$multi_img,
					'multi.URL'		=>	$link,
					'multi.NAME'	=>	$r['multi_name'],
					'img.WIDTH'		=> "150",
					'img.HEIGHT'	=> "200",
					'multi.TR'		=> $tr,
					'multi.VIEWED'	=>	$lang['num_viewed']." ".$r['multi_viewed'],
				)
			);
			$i++;
		}
		$z = $tpl->assign_vars($z,
			array(
				'multimedia.TITLE' => $cat_tit,
				'multimedia.TOTAL'	=> $total,
				'multimedia.PAGES' => $func->viewpages($tt,$conf['media_per_page'],$cmd[3],$tit_ascii),
			)
		);
		
		$z = $tpl->assign_blocks_content($z,array(
				'list_multi'	=>	$html,
			)
		);
		
	}
	else $z=box_announcement($lang['no_data']);
	$main_content=$z;
}
}
?>
